package de.chandelier.vocatra;

import java.io.File;

import org.eclipse.jface.viewers.ArrayContentProvider;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.ExpandBar;
import org.eclipse.swt.widgets.ExpandItem;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.part.ViewPart;

public class View extends ViewPart {
	public static final String ID = "de.chandelier.vocatra.view";

	private TableViewer viewer;

	/**
	 * This is a callback that will allow us to create the viewer and initialize
	 * it.
	 */
	public void createPartControl(Composite parent) {
		ExpandBar expandBar = new ExpandBar(parent, SWT.None);
		ExpandItem vocabularyItem = new ExpandItem(expandBar, SWT.NONE);
		vocabularyItem.setText("Vocabulary");
		Composite composite = new Composite(expandBar, SWT.BORDER);
		composite.setLayout(new FillLayout());
		viewer = new TableViewer(composite);
		viewer.setContentProvider(new ArrayContentProvider());
		viewer.setLabelProvider(new LabelProvider());
		viewer.setInput(new String[] { "Vokabeln Lektion 1",
				"Vokabeln Lektion 2", "Vokabeln Lektion 3" });
		vocabularyItem.setHeight(composite
				.computeSize(SWT.DEFAULT, SWT.DEFAULT).y);
		Image vocImage = new Image(Display.getDefault(),
				View.class.getResourceAsStream("/resources/vocabulary48px.png"));

		vocabularyItem.setImage(vocImage);
		vocabularyItem.setControl(composite);

		Composite grammarComposite = new Composite(expandBar, SWT.BORDER);
		grammarComposite.setLayout(new FillLayout());
		TableViewer gramarViewer = new TableViewer(grammarComposite);
		gramarViewer.setContentProvider(new ArrayContentProvider());
		gramarViewer.setLabelProvider(new LabelProvider());
		gramarViewer.setInput(new String[] { "Grammatik Lektion 1",
				"Grammatik Lektion 2", "Grammatik Lektion 4" });
		ExpandItem grammarItem = new ExpandItem(expandBar, SWT.NONE);
		grammarItem.setText("Grammar");
		grammarItem.setHeight(grammarComposite.computeSize(SWT.DEFAULT,
				SWT.DEFAULT).y);
		Image grammarImage = new Image(Display.getDefault(),
				View.class.getResourceAsStream("/resources/grammar48px.png"));
		grammarItem.setImage(grammarImage);
		grammarItem.setControl(grammarComposite);

		Composite dataStorageComposite = new Composite(expandBar, SWT.BORDER);
		dataStorageComposite.setLayout(new FillLayout());
		Button dataStorageButton = new Button(dataStorageComposite, SWT.PUSH);
		dataStorageButton.setText("Store Data Now !");
		dataStorageButton.addSelectionListener(new SelectionListener() {

			@Override
			public void widgetSelected(SelectionEvent e) {
				// TODO Auto-generated method stub
				// @DSM Put data storage logic here
				//Prints String to the Console
				System.out.println("@DSM Put data storage logic here");

			}

			@Override
			public void widgetDefaultSelected(SelectionEvent e) {
				// TODO Auto-generated method stub

			}
		});
		ExpandItem dataStorageItem = new ExpandItem(expandBar, SWT.NONE);
		dataStorageItem.setText("Data Storage");
		dataStorageItem.setImage(new Image(Display.getDefault(), View.class
				.getResourceAsStream("/resources/floppy48px.png")));
		dataStorageItem.setHeight(dataStorageComposite.computeSize(SWT.DEFAULT,
				SWT.DEFAULT).y);
		
		dataStorageItem.setControl(dataStorageComposite);

	}

	/**
	 * Passing the focus request to the viewer's control.
	 */
	public void setFocus() {
		// viewer.getControl().setFocus();
	}
}